;
(function () {
    // var dq = {
    //     "rdsub": [{
    //         "code": "CET-SET",
    //         "name": "全国大学当次英语四、六级口语考试(CET-SET)"
    //     }, {
    //         "code": "CET4",
    //         "name": "全国大学英语四级考试(CET4)"
    //     }, {
    //         "code": "CET6",
    //         "name": "全国大学英语六级考试(CET6)"
    //     }, {
    //         "code": "CJT4",
    //         "name": "全国大学日语四级考试(CJT4)"
    //     }, {
    //         "code": "CJT6",
    //         "name": "全国大学日语六级考试(CJT6)"
    //     }, {
    //         "code": "PHS4",
    //         "name": "全国大学德语四级考试(PHS4)"
    //     }, {
    //         "code": "PHS6",
    //         "name": "全国大学德语六级考试(PHS6)"
    //     }, {
    //         "code": "CRT4",
    //         "name": "全国大学俄语四级考试(CRT4)"
    //     }, {
    //         "code": "CRT6",
    //         "name": "全国大学俄语六级考试(CRT6)"
    //     }, {
    //         "code": "TFU4",
    //         "name": "全国大学法语四级考试(TFU4)"
    //     }]
    // }

    var identity;
    // var identity = '566012E6330102932B67EC82A2A21992';
    // var result = new Object();
    jsuper.config({
        ciphertext: '35a0e922ffeeac5a494265cdee8fa711',
        // ciphertext: "87bbbe833e2e1c7f3c7af1643052f63a",
        debug: false,
        success: function () {
            jsuper.userInfo({
                success: function (data) {
                    identity = data.identity;
                    ga('send', 'pageview', {
                        'dimension1': data.gender,
                        'dimension3': data.grade,
                        'dimension2': data.schoolId
                    });
                }
            })
        }
    })

    // result.publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMFBIs6VqyyxytxiY6sHocThOKoJWNSY8BuKXMilvKUsdagv44zFJvMXnV2E7ZbdjpNS1IY/uRoJzwUuob3sme0CAwEAAQ==";

    var submieType;

    function renderVerCode(data) {
        $$('#yz-code-img').setAttribute('src', data.verCodeString);
        $$('#yz-box').style.display = 'block';
        if ($$('#yz-code')) {
            $$('#yz-code').focus();
        }
    }

    function checkUrl() {
        var url = decodeURI(window.location);
        if (location.search) {
            $$("#studentNumber").value = url.split('?')[1].split('&')[0].split('=')[1]
            $$("#name").value = url.split('?')[1].split('&')[1].split('=')[1]
            submit();
        }
    }

    function checkIsBb() {
        var isBb = /SuperFriday/i.test(window.navigator.userAgent.toLowerCase());
        console.log(isBb)
        if (!isBb) {
            $$('#to-ticket-num-manager-word').style.display = 'none'
        }
    }

    checkIsBb();

    checkUrl();


    // function getKsxm(z) {
    //     var t = z.charAt(9);
    //     if (!isNaN(t)) return dq.rdsub[t];

    // }


    function submit(isChangeVerCode) {
        var param = {
            studentNumber: trim($$("#studentNumber").value),
            name: trim($$("#name").value),
            cookie: $$('#cookies').value,
            type: submieType || 0,
            changeVercode: !!isChangeVerCode,
            identity: identity
        };
        var vercode = $$('#yz-code').value;
        if (param.cookie.length > 0 && vercode.length < 1 && !isChangeVerCode) {
            toast("请输入验证码", 2);
            return false;
        }
        if (vercode.length > 0) {
            param.verCode = vercode;
        }
        if (param.studentNumber.length < 1) {
            toast("请输入准考证号", 2);
            return false;
        } else if (param.studentNumber.length != 15) {
            toast("请输入正确的准考证号", 2);
            return false;
        }
        if (param.name.length < 1) {
            toast("请输入姓名", 2);
            return false;
        }

        // var ksxmObj = getKsxm(param.studentNumber);

        // var crypt = new JSEncrypt();
        // crypt.setPublicKey(result.publicKey);
        // var czn = encodeURIComponent(crypt.encrypt((ksxmObj.code + "," + param.studentNumber + "," + param.name).replace(/\s/g, "")));
        // param.identity = czn;
        var thisBtn = $$("#submit-btn");
        thisBtn.setAttribute("disabled", true);
        thisBtn.innerHTML = '查询中...';
        ajax({
            url: dataDoor.get("getCetScore"),
            method: "post",
            dataType: 'json',
            data: param,
            onsuccess: function (data) {
                if (!data.success) {
                    if (data.verCodeString) {
                        renderVerCode(data);
                        $$('#cookies').value = data.cookies;
                        submieType = data.type;
                        if (!isChangeVerCode && data.errorCode == 103) {
                            toast('验证码错误', 2);
                            $$('#yz-code').value = '';
                        } else {
                            data.message && toast(data.message, 2);
                        }
                    } else {
                        //信息错误
                        toast(data.message, 2);
                    }
                } else {
                    $$('#cookies').value = '';
                    $$('#yz-code').value = '';
                    window.localStorage.setItem("cetScore", JSON.stringify(data.scoreCet));
                    location.href = "cetResult.html";
                }
                thisBtn.innerHTML = '查询成绩';
                thisBtn.removeAttribute("disabled");
            },
            onerror: function () {
                toast("无法连接到网络，请检查网络配置", 2);
                thisBtn.removeAttribute("disabled");
                thisBtn.innerHTML = '查询成绩';
            }
        });
    }

    //点击查询成绩
    addEvent($$("#submit-btn"), "touchend", function () {
        submit();
    });

    addEvent($$('#yz-code-change'), "touchend", function () {
        submit(true);
    });
    addEvent($$('#to-ticket-num-manager'), "touchend", function () {
        window.location.replace('./ticketNumManager.html')
    });
})()